qui(
    function (require, exports, module) {
        SysConfig.Grid = function (options) {
            this.dao = SysConfig.Dao;
            this.config = SysConfig.Config;
            this.options = options || {};
        };
        Com.inherits(SysConfig.Grid, Ancestor.Grid).extend({
            runList: function () {
                var self = this;
                self.$grid = $('#list');
                self.initDialog();
                self.initListGrid();
                self.bindEvent();
                self.config.PageBean = SysConfig.Util.createPageBean();
                self.query();
            },
            getParam:function(){
                var self = this;
                var $container = $("#QueryContainer");

                var $grid = self.$grid;
                var params = {};
                var $form = $container.find('form[name="basicFrm"]');

                var $elements = $.makeArray($form.prop('elements')).filter(function () {
                    return true; //this.name;
                });

                var name;
                var key;
                $.each($elements, function () {
                    name = this.name;
                    if (name) {

                        if (this.type == 'radio') {
                            params[name] = $('input[name="' + name + '"]:checked').val() || '';
                        } else
                            params[name] = $.trim($(this).val()) || '';

                    }

                });

                if(params['type'] != '') {
                    params.type = '%' + params.type + '%';
                }

                if(params['descr'] != '') {
                    params.descr = '%' + params.descr + '%';
                }

                return params;
            },

            verifyParams: function(params) {
                return true;
            },

            initDialog:function(){
                $("#edit-dlg").dialog({
                    title: "编目",
                    resizable: false,
                    dialogClass: 'alert',
                    autoOpen: false,
                    width: 500,
                    modal: true
                })
                $(".ui-dialog-titlebar-close").html('<span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span><span class="ui-button-text">close</span>');
            },
            initListGrid: function (options, callback) {
                var self = this;
                // var params = self.getParam();
                var gridConfig = self.getGridConfig(self.config.TABLE_LIST);
                options = $.extend(true, {}, gridConfig, options);
                self.$grid.jqGrid(options);
            },
            query: function () {
                var self = this;
                var params = self.getParam();
                if(!self.verifyParams(params)) {
                    return;
                }

                self.dao.doQuery(params, function (data) {
                    var retValue = null;
                    if (data.code === "A00000" && data.data != null ) {
                        data.data.sort(SysConfig.Config.SORT_RULE.asc_type_key);
                        self.config.PageBean.setNewData(data.data,40);
                    } else {
                        self.config.PageBean.setNewData([]);
                    }
                    retValue = self.config.PageBean.goToFirst();
                    self.$grid[0].addJSONData(retValue)

                });
            },
            bindEvent: function() {
                var self= this;
                self.bindBasicEvent();

            },
            bindBasicEvent: function() {
                var self = this;
                var $container = $("#QueryContainer");
                var $form = $container.find('form[name="basicFrm"]');
                self.bindFormEvent($form);
                $container.find('.query-btn').on('click.query', function () {
                    self.query();
                    return false;
                });

                //$form.find('button[type="reset"]').click(function() {
                //    self.resetQueryForm();
                //});

                //$form.find('input[name=streamName]').keydown(function(e){
                //    if(e.keyCode==13){
                //        self.query();
                //    }
                //})
            },

            bindFormEvent: function() {

            }
        })
    }
);